// 列表头按钮配置
import {getDict} from "@/api/common";

export const operateList = [
  {
    name: $i18n.t("common.add"),
    type: "primary",
    icon: "el-icon-circle-plus-outline",
    handleName: "add", // 点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    icon: "el-icon-delete",
    handleName: "deleteBatch", // 点击时返回的标识
    isMultiple: true,
  },
];
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", // 点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", // 点击时返回的标识
  },
];
// 搜索条件配置
export const searchConfig = {
  data() {
    const self = this;
    return {
      searchDialog: {
        inline: true,
        formDesc: {
          materialType: {
            type: "select",
            label: '类型',
            prop: {
              text: "description",
              value: "value"
            },
            // Promise 对象
            options: async (data) => {
              const list = await getDict("tm_material_base")
              return list.data.result
            }
          },
          materialCode: {
            type: "input",
            label: '物料编号',
          },
          materialName: {
            type: "input",
            label: '物料名称',
          },
        },
      },
    };
  },
};
// 品牌搜索条件配置
export const detailSearchConfig = {
  data () {
    const _this = this;
    return {
      detailSearchConfig: {
        inline: true,
        formDesc: {
          brand: {
            type: "input",
            layout: 8,
            label: '品牌',
          }
        },
      },
    };
  },
};
// 新增/删除表单配置
export const formDescDialogMixin = {
  data() {
    const self = this;
    return {
      formDescDialog: {
        span: 24,
        formDesc: {
          materialType: {
            layout: 24,
            type: "select",
            label: '类型',
            prop: {
              text: "description",
              value: "value"
            },
            // Promise 对象
            options: async (data) => {
              const list = await getDict("tm_material_base")
              return list.data.result
            }
          },
          materialCode: {
            layout: 24,
            type: "input",
            label: '物料编号',
          },
          materialName: {
            layout: 24,
            type: "input",
            label: '物料名称',
          },
          materialUnit: {
            layout: 24,
            type: "select",
            label: '物料单位',
            prop: {
              text: "description",
              value: "value"
            },
            // Promise 对象
            options: async (data) => {
              const list = await getDict("material_unit")
              return list.data.result
            }
          },
          materialSafetyStock: {
            layout: 24,
            type: "number",
            label: '安全库存',
          },
        },
      },
    };
  },
};

// 新增/删除 品牌表单配置
export const subFormDescDialogMixin = {
  data() {
    const self = this;
    return {
      subFormDescDialog: {
        span: 24,
        formDesc: {
          materialCode: {
            layout: 24,
            type: "input",
            label: '物料编号',
            disabled: true,
          },
          brand: {
            layout: 24,
            type: "input",
            label: '品牌名称',
          },
        },
      },
    };
  },
};
export const subUnitFormDescDialogMixin = {
  data() {
    const self = this;
    return {
      subUnitFormDescDialog: {
        span: 24,
        formDesc: {
          materialCode: {
            layout: 24,
            type: "input",
            label: '物料编号',
            required: true,
            disabled: true,
          },
          unit: {
            layout: 24,
            type: "input",
            required: true,
            label: '规格',
          },
          packUnit: {
            layout: 24,
            type: "select",
            required: true,
            label: '包装单位',
            prop: {
              text: "description",
              value: "value"
            },
            // Promise 对象
            options: async (data) => {
              const list = await getDict("material_pack_unit")
              return list.data.result
            },
            on: {
              change: (val) => {
                if (val === '无') {
                  self.packUnitChange(val);
                }
              },
            },
          },
          packCapacity: {
            layout: 24,
            required: true,
            type: "number",
            label: '包装容量',
            disabled: (data) => {
              return data.packUnit==='无' ?  true : false;
            },
          },
          countType: {
            layout: 24,
            type: "select",
            required: true,
            label: "库存统计方式",
            prop: {
              value: "value",
              text: "text",
            },
            disabled: (data) => {
              return data.packUnit==='无' ?  true : false;
            },
            options: [
              {
                value: "1",
                text: "根据基础单位"
              },
              {
                value: "2",
                text: "根据包装数量"
              },
            ],
          },
        },
      },
    };
  },
};
